#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#pragma pack(1)

typedef struct{
	char head[384];
	unsigned short nblock;
}dat_head;

typedef struct{
	char name[9];
	unsigned short nstock;
	unsigned short type;
	char stock_code[2800];
}block_item;

int read_dat(char * file_name);

char  * prefix_tnf = "E:\\hubin\\st\\new_gxzq_v6-1\\T0002\\hq_cache\\";
char *  code_file[] = { "block_fg.dat", "block_zs.dat", "block_gn.dat" };
int main(int argc, char *argv[])
{
	char file_name[1024];

	for (int i = 0; i < 3; i++) {
		strcpy(file_name, prefix_tnf);
		strcat(file_name, code_file[i]);
		read_dat(file_name);
	}

}
int read_dat(char * file_name)
{
	FILE *fp;
	if ((fp = fopen(file_name, "rb")) == NULL)
	{
		printf("Error: Can't open :%s! ", file_name);
		return -1;
	}
	int ndata = 0;

	dat_head head;
	fread(&head, sizeof(dat_head), 1, fp);
	printf("\n%s %d", file_name, head.nblock);

	block_item item;
	int n = 1;
	while (fread(&item, sizeof(block_item), 1, fp) > 0){
		printf("\n%d %s   %u    %u", n++ , item.name, item.nstock,item.type);
		char * p = item.stock_code;
		
		for (int i = 0; i < 400; i++, p += 7){
			if (!*p){
				break;
			}

			if (i % 8 == 0){
				printf("\n");
			}

			printf("%d  %s  ", i, p);
		}
		_getch();
	}

	fclose(fp);

	if (_getch() == 0) _getch();
	return 0;
}
